$(function(){
    let radius = 50;
    var width = $('#earth').width();
    var height = $('#earth').height();

    //场景
    var scene = new THREE.Scene();
    var axesHelper = new THREE.AxesHelper( 500 );
    scene.add( axesHelper );

    //相机
    var camera = new THREE.PerspectiveCamera(45, width / height, 1, 1500);
    camera.position.x = -150;
    camera.position.y = 150;
    camera.position.z = -150;
    //camera.lookAt({ x: 100, y:100, z: 100 });

    var earthGeo = new THREE.SphereGeometry(radius, 100, 100);
    var earthMater = new THREE.MeshPhongMaterial({
        //map: new THREE.TextureLoader().load('assets/images/earth.jpg'),
        color: '#e3e3e3',
        side: THREE.DoubleSide
    });

    var earthMesh = new THREE.Mesh(earthGeo, earthMater);
    //scene.add(earthMesh);

    //添加立方体
    var len = 12, wid = 8;
    var shape = new THREE.Shape();
shape.moveTo( 0,0 );
shape.lineTo( 0, wid );
shape.lineTo( len, wid );
shape.lineTo( len, 0 );
shape.lineTo( 0, 0 );

var extrudeSettings = {
	steps: 2,
	depth: 16,
	bevelEnabled: true,
	bevelThickness: 1,
	bevelSize: 1,
	bevelOffset: 0,
	bevelSegments: 1
};

var geometry = new THREE.ExtrudeGeometry( shape, extrudeSettings );
var material = new THREE.MeshBasicMaterial( { color: 0xe3e3e3 } );
var mesh = new THREE.Mesh( geometry, material ) ;
// mesh.position.x = -60;
// mesh.position.y = 60;
// mesh.position.z = -60;
scene.add( mesh );

    // 光
    var light = new THREE.HemisphereLight(0x0000ff, 0x0000ff, 1);
    scene.add(light);
     // 渲染器
     var renderer = new THREE.WebGLRenderer({
        alpha: true,
        antialias: true,
        preserveDrawingBuffer: true
    });
    $('#earth').html(renderer.domElement);
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(width, height);

    // 载入控制器
    var controls = new THREE.OrbitControls(camera, renderer.domElement);

    function animate() {
        //mesh.rotation.y += 0.01;
        
        controls.update();
        renderer.render(scene, camera);
        requestAnimationFrame(animate);
    }

    animate();
});